
#include <iostream>
#include <cmath>
#include <vector>
#include <string>

bool Prosto(int n) {
    bool t = true;
    for (int i = 2; i <= static_cast<int>(std::sqrt(n)) + 1; i++) {
        if (n % i == 0) {
            t = false;
            break;
        }
    }
    return t;
}

int main() {
    std::string s;
    std::getline(std::cin, s);
    std::vector<std::string> alf = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::vector<std::string> words;
    std::string word = "";
    for (char c : s) {
        if (c == ' ') {
            words.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    words.push_back(word);

    if (words.size() == 3 && words[0] in alf && words[1] in alf && words[2] in alf) {
        int chislo = alf.index(words[0]) * 100 + alf.index(words[1]) * 10 + alf.index(words[2]);
        int p = 0;
        if (Prosto(chislo)) {
            p = chislo;
        } else {
            for (int i = chislo - 1; i > 2; i--) {
                if (Prosto(i)) {
                    p = i;
                    break;
                }
            }
            for (int i = chislo + 1; i < 1500; i++) {
                if (Prosto(i) && (chislo - p) > (i - chislo)) {
                    p = i;
                    break;
                }
            }
        }
        std::cout << p << std::endl;
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}
